<!DOCTYPE html>
<html lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>GCC 4.3 Release Series &mdash; Porting to the New Tools</title>
<link rel="stylesheet" type="text/css" href="https://gcc.gnu.org/gcc.css" />
</head>

<body>
<h1>GCC 4.3 Release Series<br />Porting to the New Tools</h1>

<p>
The GCC 4.3 release series differs from previous GCC releases in more
than the usual list of <a href="changes.html">new
features</a>. Some of these changes are a result of bug fixing, and
some old behaviors have been intentionally changed in order to support
new standards, or relaxed in standards-conforming ways to facilitate
compilation or runtime performance. Some of these changes are not
visible to the naked eye, and will not cause problems when updating
from older GCC versions.
</p>

<p>
However, some of these changes are visible, and can cause grief to
users porting to GCC 4.3. This document is an effort to identify major
issues and provide clear solutions in a quick and easily-searched
manner. Additions and suggestions for improvement are welcome.
</p>

<h2>C language issues</h2>

<h3>Semantic change of extern inline</h3>

<p>
When compiling with <code>-std=c99</code> or <code>-std=gnu99</code>,
the <code>extern inline</code> keywords changes meaning. GCC 4.3
conforms to the ISO C99 specification, where <code>extern
inline</code> is very different thing than the GNU <code>extern
inline</code> extension. For the following code compiled
with <code>-std=c99</code>,
</p>

<pre>
extern inline int
foo()
{ return 5; }
</pre>

<p>Will result in a function definition for <code>foo</code> being
emitted in the subsequent object file, whereas previously there was none. As a
result, files that use this extension and compile in the C99 dialect
will see many errors of the form:
</p>

<pre>
multiple definition of `foo'
first defined here
</pre>

<p>When linking together multiple object files.</p>

<p>
If the old GNU extern inline behavior is desired, one can
use <code>extern inline __attribute__((__gnu_inline__))</code>. The
use of this attribute can be guarded by <code>#ifdef
__GNUC_STDC_INLINE__</code> which is a macro which is defined when
inline has the ISO C99 behavior. Alternatively the code can be compiled
with the <code>-fgnu89-inline</code> option.
</p>

<p>The resulting, changed code looks like:</p>

<pre>
extern inline __attribute__((__gnu_inline__)) int
foo()
{ return 5; }
</pre>

<h3>New warnings</h3>

<p>Significant changes were made to <code>-Wconversion</code>.  In
addition, improvements to the GCC infrastructure allow improvements in
the ability of several existing warnings to spot problematic code. As
such, new warnings may exist for previously warning-free code that
uses
<code>-Wuninitialized</code>, <code>-Wstrict-aliasing </code>, <code>-Wunused-function</code>, <code>-Wunused-variable</code>. Note
that <code>-Wall</code> subsumes many of these warning flags.
</p>

<p> Although these warnings will
not result in compilation failure, often <code>-Wall</code> is used in
conjunction with <code>-Werror</code> and as a result, new warnings
are turned into new errors.
</p>

<p>As a workaround, remove <code>-Werror</code> until the new warnings
are fixed, or for conversion warnings add <code>-Wno-conversion</code>.
</p>

<h2>C++ language issues</h2>

<h3>Header dependency cleanup</h3>

<p>
As detailed
here <a href="https://gcc.gnu.org/onlinedocs/libstdc++/manual/api.html#api.rel_430">(Header dependency streamlining)</a>, many of the standard C++ library
include files have been edited to only include the smallest
possible number of additional files. As such, many C++ programs that
used <code>std::memcpy</code> without including &lt;cstring&gt;, or
used <code>std::auto_ptr</code> without including &lt;memory&gt; will
no longer compile.
</p>

<p>
Usually, this error is of the form:
</p>

<pre>
error: 'strcmp' was not declared in this scope
</pre>

<p>The table below shows some of the missing items, and the header
file that will have to be added as an #include for the compile to
succeed.
</p>

<table class="border">
  <tr>
    <th>If missing</th>
    <th>Then include this header</th>
  </tr>
  <tr>
    <td>find, for_each, sort</td>
    <td>&lt;algorithm&gt;</td>
  </tr>
  <tr>
    <td>ostream_iterator, istream_iterator</td>
    <td>&lt;iterator&gt;</td>
  </tr>
  <tr>
    <td>auto_ptr</td>
    <td>&lt;memory&gt;</td>
  </tr>
  <tr>
    <td>typeid</td>
    <td>&lt;typeinfo&gt;</td>
  </tr>
  <tr>
    <td>isalnum, toupper</td>
    <td>&lt;cctype&gt;</td>
  </tr>
  <tr>
    <td>INT_MIN, INT_MAX, RAND_MAX</td>
    <td>&lt;climits&gt;</td>
  </tr>
  <tr>
    <td>printf</td>
    <td>&lt;cstdio&gt;</td>
  </tr>
  <tr>
    <td>atoi, free, rand, exit</td>
    <td>&lt;cstdlib&gt;</td>
  </tr>
  <tr>
    <td>EXIT_FAILURE</td>
    <td>&lt;cstdlib&gt;</td>
  </tr>
  <tr>
    <td>strcmp, strdup, strcpy, memcpy</td>
    <td>&lt;cstring&gt;</td>
  </tr>
</table>

<h3>Removal of Pre-ISO headers</h3>

<p>Various backwards and deprecated headers have been removed.
</p>


<table class="border">
  <tr>
    <th>If missing</th>
    <th>Then include this header</th>
  </tr>
  <tr>
    <td>&lt;algobase.h&gt;</td>
    <td>&lt;algorithm&gt;</td>
  </tr>
  <tr>
    <td>&lt;algo.h&gt;</td>
    <td>&lt;algorithm&gt;</td>
  </tr>
  <tr>
    <td>&lt;alloc.h&gt;</td>
    <td>&lt;memory&gt;</td>
  </tr>
  <tr>
    <td>&lt;bvector.h&gt;</td>
    <td>&lt;vector&gt;</td>
  </tr>
  <tr>
    <td>&lt;complex.h&gt;</td>
    <td>&lt;complex&gt;</td>
  </tr>
  <tr>
    <td>&lt;defalloc.h&gt;</td>
    <td>&lt;memory&gt;</td>
  </tr>
  <tr>
    <td>&lt;deque.h&gt;</td>
    <td>&lt;deque&gt;</td>
  </tr>
  <tr>
    <td>&lt;fstream.h&gt;</td>
    <td>&lt;fstream&gt;</td>
  </tr>
  <tr>
    <td>&lt;function.h&gt;</td>
    <td>&lt;functional&gt;</td>
  </tr>
  <tr>
    <td>&lt;hash_map.h&gt;</td>
    <td>&lt;tr1/unordered_map&gt;</td>
  </tr>
  <tr>
    <td>&lt;hashtable.h&gt;</td>
    <td>&lt;tr1/unordered_map&gt; or &lt;tr1/unordered_set&gt;</td>
  </tr>
  <tr>
    <td>&lt;heap.h&gt;</td>
    <td>&lt;queue&gt;</td>
  </tr>
  <tr>
    <td>&lt;iomanip.h&gt;</td>
    <td>&lt;iomanip&gt;</td>
  </tr>
  <tr>
    <td>&lt;iostream.h&gt;</td>
    <td>&lt;iostream&gt;</td>
  </tr>
  <tr>
    <td>&lt;istream.h&gt;</td>
    <td>&lt;istream&gt;</td>
  </tr>
  <tr>
    <td>&lt;iterator.h&gt;</td>
    <td>&lt;iterator&gt;</td>
  </tr>
  <tr>
    <td>&lt;list.h&gt;</td>
    <td>&lt;list&gt;</td>
  </tr>
  <tr>
    <td>&lt;map.h&gt;</td>
    <td>&lt;map&gt;</td>
  </tr>
  <tr>
    <td>&lt;multimap.h&gt;</td>
    <td>&lt;map&gt;</td>
  </tr>
  <tr>
    <td>&lt;multiset.h&gt;</td>
    <td>&lt;set&gt;</td>
  </tr>
  <tr>
    <td>&lt;new.h&gt;</td>
    <td>&lt;new&gt;</td>
  </tr>
  <tr>
    <td>&lt;ostream.h&gt;</td>
    <td>&lt;ostream&gt;</td>
  </tr>
  <tr>
    <td>&lt;pair.h&gt;</td>
    <td>&lt;utility&gt;</td>
  </tr>
  <tr>
    <td>&lt;queue.h&gt;</td>
    <td>&lt;queue&gt;</td>
  </tr>
  <tr>
    <td>&lt;rope.h&gt;</td>
    <td>&lt;ext/rope&gt;</td>
  </tr>
  <tr>
    <td>&lt;set.h&gt;</td>
    <td>&lt;set&gt;</td>
  </tr>
  <tr>
    <td>&lt;slist.h&gt;</td>
    <td>&lt;ext/slist&gt;</td>
  </tr>
  <tr>
    <td>&lt;stack.h&gt;</td>
    <td>&lt;stack&gt;</td>
  </tr>
  <tr>
    <td>&lt;streambuf.h&gt;</td>
    <td>&lt;streambuf&gt;</td>
  </tr>
  <tr>
    <td>&lt;stream.h&gt;</td>
    <td>&lt;iostream&gt;</td>
  </tr>
  <tr>
    <td>&lt;tempbuf.h&gt;</td>
    <td>&lt;ext/memory&gt;</td>
  </tr>
  <tr>
    <td>&lt;tree.h&gt;</td>
    <td>&lt;ext/rb_tree&gt; or &lt;ext/pb_ds/assoc_container.hpp&gt;</td>
  </tr>
  <tr>
    <td>&lt;vector.h&gt;</td>
    <td>&lt;vector&gt;</td>
  </tr>
</table>

<p>For future reference, available headers are listed in the <a
href="https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_headers.html">libstdc++
manual</a>.
</p>

<p>An example.</p>

<pre>
#include &lt;iostream.h&gt;

int main()
{
  cout &lt;&lt; "I'm too old" &lt;&lt; endl;
  return 0;
}
</pre>

<p>
Compiling with previous compilers gives:
</p>

<pre>
warning: #warning This file includes at least one deprecated or
antiquated header. Please consider using one of the 32 headers found
in section 17.4.1.2 of the C++ standard. Examples include substituting
the &lt;X&gt; header for the &lt;X.h&gt; header for C++ includes, or
&lt;iostream&gt; instead of the deprecated header
&lt;iostream.h&gt;. To disable this warning use -Wno-deprecated.
</pre>

<p>
But now says:
</p>

<pre>
error: iostream.h: No such file or directory
In function 'int main()':
6: error: 'cout' was not declared in this scope
6: error: 'endl' was not declared in this scope
</pre>

<p>Fixing this is easy, as demonstrated below.
</p>

<pre>
#include &lt;iostream&gt;
using namespace std;

int main()
{
  cout &lt;&lt; "I work again" &lt;&lt; endl;
  return 0;
}
</pre>

<p>Note that explicitly qualifying <code>cout</code> as <code>std::cout</code> and likewise for <code>endl</code> instead of globally injecting the <code>std</code> namespace (ie, <code>using namespace std</code>) will also work. 
</p>

<h3>Name lookup changes</h3>
<p>
GCC by default no longer accepts code such as
</p>
<pre>
template &lt;class _Tp&gt; class auto_ptr {};
template &lt;class _Tp&gt;
struct counted_ptr
{
  auto_ptr&lt;_Tp&gt; auto_ptr();
};
</pre>

<p>  but will issue the diagnostic</p>

<pre>
error: declaration of 'auto_ptr&lt;_Tp&gt; counted_ptr&lt;_Tp&gt;::auto_ptr()'
error: changes meaning of 'auto_ptr' from 'class auto_ptr&lt;_Tp&gt;'
</pre>

<p>
The reference to struct <code>auto_ptr</code> needs to be qualified
here, or the name of the member function changed to be unambiguous.
</p>

<pre>
template &lt;class _Tp&gt; class auto_ptr {};
template &lt;class _Tp&gt;
struct counted_ptr
{
  ::auto_ptr&lt;_Tp&gt; auto_ptr();
};
</pre>

<p>In addition, <code>-fpermissive</code> can be used as a temporary
workaround to convert the error into a warning until the code is
fixed. Note that then in some case name lookup will not be standard
conforming.
</p>

<h3>Duplicate function parameters</h3>

<p>Duplicate function parameters are now treated uniformly as an error
in C and C++. 
</p>

<pre>
void foo(int w, int w);
</pre>

<p>
Now gives the following, re-worded error for both C and C++:
</p>

<pre>
error: multiple parameters named 'w'
</pre>

<p>To fix, rename one of the parameters something unique.
</p>

<pre>
void foo(int w, int w2);
</pre>


<h3>Stricter requirements for function main signature</h3>

<p>The two-argument signature for main has <code>int</code> as the
first argument. GCC 4.3 rigorously enforces this.
</p>

<pre>
int main(unsigned int m, char** c) 
{ return 0; }
</pre>

<p>Gives:</p>

<pre>
error: first argument of 'int main(unsigned int, char**)' should be 'int'
</pre>

<p>Fixing this is straightforward: change the first argument to be of
type <code>int</code>, not <code>unsigned int</code>. As transformed:
</p>

<pre>
int main(int m, char** c) 
{ return 0; }
</pre>

<h3>Explicit template specialization cannot have a storage class</h3>

<p>Specializations of templates cannot explicitly specify a storage
class, and have the same storage as the primary template. This is a
change from previous behavior, based on the feedback and commentary as
part of the ISO C++ Core Defect
Report <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#605">605</a>.
</p>

<pre>
template&lt;typename T&gt;
  static void foo();

template&lt;&gt;
  static void foo&lt;void&gt;();  
</pre>

<p>Gives:</p>

<pre>
error: explicit template specialization cannot have a storage class
</pre>

<p>This also happens with the <code>extern</code> specifier. Fixing
this is easy: just remove any storage specifier on the specialization. Like so:
</p>

<pre>
template&lt;typename T&gt;
  static void foo();

template&lt;&gt;
  void foo&lt;void&gt;();  
</pre>

<h2>Java issues</h2>

<h3>Java 1.2 and earlier requires upgraded <code>ant</code></h3>

<p>The use of the Eclipse Java compiler in GCC 4.3 enables the use of
all 1.5 language features, but use with older versions of
the <code>ant</code> build tool are problematic. Typical errors of
this sort look like:
</p>

<pre>
[javac] source level should be comprised in between '1.3' and '1.6' (or '5', '5.0', ..., '7' or '7.0'): 1.2
</pre>

<p>To successfuly use the earlier java dialects with GCC, please use this patch:
</p>

<pre>
svn diff -r529854:529855 http://svn.apache.org/repos/asf/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
</pre>

<h2>Links</h2>

<p>
Jakub Jelinek,
<a href="https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/thread/WV3KUDEP2JNOWGWES42RQZFYFNLFLAMJ/">
Mass rebuild status with gcc-4.3.0-0.4 of rawhide-20071220</a>
</p>

<p>
Simon Baldwin, <a href="https://gcc.gnu.org/ml/gcc-patches/2007-03/msg01962.html">
[PATCH][RFC] C++ error for parameter redefinition in function prototypes
</a>
</p>

<p>
Simon Baldwin, <a href="https://gcc.gnu.org/ml/gcc-patches/2007-06/msg01075.html">
[REVISED PATCH][RFC] Fix PR c++/31923: Storage class with explicit template specialization
</a>
</p>

</body>
</html>
